#ifndef HEM1604_H
#define HEM1604_H

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MAX3(a, b, c) MAX(MAX(a, b), c)
#define MIN3(a, b, c) MIN(MIN(a, b), c)

// HEMxxxxC系列扩展IO模块节点ID定义
#define NODEID_HEM1601       0x00
#define NODEID_HEM1601_LAST  0x07
#define NODEID_HEM1602       0x08
#define NODEID_HEM1602_LAST  0x0f
#define NODEID_HEM2001       0x10
#define NODEID_HEM2001_LAST  0x17
#define NODEID_HEM1604       0x38
#define NODEID_HEM1604_LAST  0x3f
// 后续备用

// HEC1016主控与HEM扩展IO模块CAN通信ID定义
#define	ID_DOWN_PWM0003  			0x0c100000
#define	ID_DOWN_PWM6063  			0x0c100f00
#define	ID_DOWN_PWMI0003  			0x0c101000
#define	ID_DOWN_PWMI6063  			0x0c101f00
#define	ID_DOWN_AO0003  			0x0c102000
#define	ID_DOWN_AO1215  			0x0c102300
#define	ID_DOWN_DO					0x0c102400
#define	ID_DOWN_DOL					0x0c102500
#define ID_DOWN_HBRIDGE             0x0C102600

#define	ID_DOWN_SET_PARA  			0x0c000000
#define	ID_UP_ACK_PARA    			0x00300000
#define	CMD_SET_PARA_NODEID       	0x01
#define	CMD_SET_PARA_BAUDRATE     	0x02
#define	CMD_SET_PARA_INMODE       	0x03
#define	CMD_SET_PARA_AIDEADZONE   	0x04
#define	CMD_SET_PARA_ERRINTERVAL  	0x05
#define	CMD_SET_PARA_UP_CYCLE_MAX 	0x06
#define CMD_SET_PARA_UP_CYCLE_MIN 	0x07
#define CMD_SET_PARA_PWMI_PID     	0x08
#define CMD_SET_PARA_PORT_MODE      0x09
#define CMD_SET_PARA_PWM_FREQ       0x0A
#define	ID_UP_AI0003                0x1c100000
#define	ID_UP_AI6063  	            0x1c100f00
#define	ID_UP_PWMI0003              0x1c101000
#define	ID_UP_PWMI6063              0x1c101f00
#define	ID_UP_PIF0003  	            0x1c102000
#define	ID_UP_PIF2831  	            0x1c102700
#define	ID_UP_PIC0001  	            0x1c102800
#define	ID_UP_PIC1415  	            0x1c102f00
#define	ID_UP_DI   		            0x1c103000
#define	ID_UP_ERR  		            0x1c131000



#define HEM_AI_NUM 		     2//普通AI
#define HEM_DI_NUM 		    14
#define HEM_PIC_NUM 	     0
#define HEM_PIF_NUM 	     0
#define HEM_DO_NUM 		    14
#define HEM_DOL_NUM          0
#define HEM_AO_NUM 		     0
#define HEM_PWM_NUM 	    14
#define HEM_PWM_FREQ_NUM     4
#define HEM_PWMI_NUM 	    14//14 pwmi
#define HEM_DO_DI_NUM       14

typedef struct io 
{
#if HEM_AI_NUM > 0
  uint32_t ai[HEM_AI_NUM];
  uint32_t inmode[16];//0:0~5V;1:0~36V;2:4~20mA
#endif
#if HEM_DI_NUM > 0
  uint32_t di[HEM_DI_NUM];
#endif
#if HEM_PI_NUM > 0
  uint32_t pi[HEM_PI_NUM];
#endif
#if HEM_DO_NUM > 0
  uint32_t dout[HEM_DO_NUM];
#endif
#if HEM_DOL_NUM >0
  uint32_t dol_out[HEM_DOL_NUM];
#endif
#if HEM_DOL_NUM >0
  uint32_t Hbridge_out[HEM_DOL_NUM];
#endif
#if HEM_AO_NUM > 0
  uint32_t ao[HEM_AO_NUM];
#endif
#if HEM_PWM_NUM > 0
  uint32_t pwm[HEM_PWM_NUM];
#endif
#if HEM_PWMI_NUM > 0
  uint32_t pwmi[HEM_PWMI_NUM];
  uint32_t ai_pwmi[HEM_PWMI_NUM];
#endif
}io_t;

#endif

